// const PaneTemplate = [
//   { color: '灰', done: false },
//   { color: '银', done: false },
//   { color: '青', done: false },
//   { color: '粉', done: false },
//   { color: '橙', done: false },
//   { color: '黄', done: false },
// ]

let panePool = []
const MAX_PANE_COUNT_PER_COLOR = 20
const COLOR_COUNT = 5
const PANE_PER_TABLE = 4

// 初始池（20*5）的玻璃池
function initPaneFactory() {
  panePool = []
  for (let i = 0; i < MAX_PANE_COUNT_PER_COLOR; i++) {
    for (let j = 0; j < COLOR_COUNT; j++) {
      panePool.push(j)
    }
  }
  // 随机交换顺序
  for (let i = 0; i < MAX_PANE_COUNT_PER_COLOR * COLOR_COUNT; i++) {
    let r = parseInt(Math.random() * 100, 10)
    let tmp = panePool[r]
    panePool[r] = panePool[i]
    panePool[i] = tmp
  }
}

function createSmallTable(playerCount) {
  let result = []
  let tableCount = 2 * playerCount + 1
  for (let i = 0; i < tableCount; i++) {
    let t = []
    for (let j = 0; j < PANE_PER_TABLE; j++) {
      t.push(panePool.shift())
    }
    result.push(t)
  }
  return result
}

function paneRecycle(pane) {
  // 加入到玻璃池的随机位置
  let randomIndex = parseInt(Math.random() * panePool.length, 10)
  panePool.splice(randomIndex, 0, pane)
}

function createBigTable() {
  return panePool
}

function getPanePool() {
  return panePool
}

export {
  createSmallTable,
  paneRecycle,
  initPaneFactory,
  getPanePool
}